package com.api.oa.mapper;

import com.api.oa.model.entity.OaNotice;
import com.api.oa.model.entity.OaRelation;
import com.api.oa.model.vo.OaRelationVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface OaOrgNoticeRelationMapper {


	@Insert("insert into aoa_notice_user_relation (" +
			"isRead," +
			"relationNoticeId," +
			"uploadFileId," +
			"relationOrgId," +
			"updatedAt" +
			") " +
			"values " +
			"(" +
			"#{business.isRead}," +
			"#{business.relationNoticeId}," +
			"#{business.uploadFileId}," +
			"#{business.relationOrgId}," +
			"#{business.updatedAt}" +
			")" )
	@Options(useGeneratedKeys = true, keyProperty = "relationId", keyColumn = "id")
	Integer insert(@Param("business") OaRelation business);


	@Update("update aoa_notice_user_relation set classifyName = #{org.classifyName}, classifyPid=#{org.classifyPid} where classifyId = #{org.classifyId}")
	Long update(@Param("org") OaRelation org);

	//设置已经读取
	@Update("update aoa_notice_user_relation set isRead =#{isRead} where relationId = #{relationId}")
	Long updateRead(@Param("relationId") Long relationId,@Param("isRead") Integer isRead);

     //通知下的机构
	@Select("select aoa_notice_user_relation.* ,d.`uname` as orgUserName,d.orgId,d.orgName  from aoa_notice_user_relation left join (select * from oa_org LEFT JOIN yq_user ON  yq_user.userId = oa_org.orgUserId) d on aoa_notice_user_relation.relationOrgId = d.orgId   where relationNoticeId = #{id}")
	List<OaRelationVO> listUnderNotice(@Param("id") Long noticeId);

	@Delete("delete from aoa_notice_user_relation where relationId=#{id}")
	void delete(@Param("id") Long id);

    //查看通知下的机构 已经读取
	@Select("select * from aoa_notice_user_relation where relationOrgId = #{id}")
	List<OaRelation> list(@Param("id") Long relationOrgId);


	@Select("select * from aoa_notice_user_relation where relationOrgId = #{id} limit 1")
	OaNotice findOne(@Param("id") Long id);

	//下发机构上传文件
	@Update("update aoa_notice_user_relation set  uploadFileId=#{uploadFileId} where relationId = #{relationId}")
	Integer noticeReplay(@Param("relationId") Long id, @Param("uploadFileId") Long fileId);
}
